<template>
	<om-formsub-outer :index="index" :checkedit="checkedit">
		<om-autoform ref="autoform" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {buildSubFormData, subOnLoad, changeEditor,configSelectData,hasValue} from '../../../static/js/formUtil.js';
	import { ignoreHtml,ptFloat,minusF,getDateStr} from '@/static/js/common.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData({
				exists:"",
				infonameId:''
			})
		},
		methods:{
			onSelectHandleWay(item){
				let _that = this
				if(item.code == '37697'){
					_that.$refs.autoform.changeEditor("applyResignPosInfo","effectDate","type","datebox")
					_that.$refs.autoform.changeEditor("applyResignPosInfo","effectDate","prompt","请输入")
				}else{
					_that.$refs.autoform.clear("applyResignPosInfo","effectDate")
					_that.$refs.autoform.changeEditor("applyResignPosInfo","effectDate","type","labelbox")
				}
			},
			initload(){
				let _that = this
				let arr = [
					_that.om.request(
						"trApply/getPosList",
						{
							lList:_that.exists,
							userId:_that.infonameId,
						}
					)
				]
				Promise.all(arr).then(res=>{
					_that.$refs.autoform.changeEditor("applyResignPosInfo","posId","data",configSelectData(res[0],"posid","posname"))
					_that.$refs.autoform.initSelectIndex("applyResignPosInfo","posId")
					if(_that.formdata.handleWayCode){
						_that.onSelectHandleWay({code:_that.formdata.handleWayCode})
					}
				})
			},
			onSelectPos(item){
				let _that = this
				_that.$refs.autoform.formdata.idCode = item.idcode
				_that.$refs.autoform.formdata.instShortName = item.instname
				_that.$refs.autoform.formdata.orgShortName = item.orgname
				_that.$refs.autoform.clear("applyResignPosInfo","handleWayCode")
				_that.isRedPos(item.posid)
			},
			isRedPos(id){
				let _that = this
				_that.om.request(
					"tposition/isRedPos",
					{
						posId:id
					}
				).then(res=>{
					_that.getHandleWayList(id,res.value)
				})
			},
			getHandleWayList(id,isRed){
				let _that = this
				_that.om.request(
					"dictZero/getHandleWayList",
					{
						code:"HRS0105",
						isRed:isRed
					}
				).then(res=>{
					_that.$refs.autoform.changeEditor("applyResignPosInfo","handleWayCode","data",configSelectData(res,"code","dicname"))
					_that.$refs.autoform.initSelectIndex("applyResignPosInfo","handleWayCode")
				})
			}
		},
		onShow() {
			
		},
		onLoad(e) {
			let _that = this
			subOnLoad(_that, e, function() {
			if(e.configDataCacheKey){
				_that.infonameId = e.infonameId
				_that.exists = _that.datas.filter((e,i)=>{
					return (i != _that.index)
				}).map(e=>e.posId).join(",")
				uni.getStorage({
					key: e.configDataCacheKey,
					success: function(res) {
						if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
							_that.autoformdata = res.data
							Object.assign(_that.initValue, _that.formdata)
							_that.autoformdata[0].order = _that.order
							_that.initload()
								if(_that.formdata.posId){
									_that.isRedPos(_that.formdata.posId)
								}
							}
						}
					})
				}		
			})
			
		}
	}
</script>

<style>
</style>                                                                                                                                                                                                                                                                                                                                                                                                                                                  
